import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class ChatServer {
    public static void main(String[] args) {
        try {
            ServerSocket server = new ServerSocket(9900);
            Socket socket =server.accept();
            //接收客户端输入吧的姓名,使用输入流InputStream
            InputStream in = socket.getInputStream();
            //封装成高级的输入流
            ObjectInputStream ois = new ObjectInputStream(in);
            String name = (String) ois.readObject();
            System.out.println(name+"进入聊天室");
            //返回给客户端欢迎信息，用到输出流对象
            OutputStream os = socket.getOutputStream();
//封装成高级的对象输出流
            ObjectOutputStream oos = new ObjectOutputStream(os);
            oos.writeObject("欢迎您，"+name);

        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
}
